/**
 * Created by zby on 2018/4/19.
 */

import java.lang.*;
import java.sql.*;

public class Age {
    public static void main(String args[]) {
        Connection con = null;
        Statement sql;
        ResultSet rs;
        String name1 = new String("");
        String name2 = new String("");
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (Exception e) {
        }
        String uri = "jdbc:mysql://localhost:3306/world?useSSL=true";
        String user = "root";
        String password = "";
        // String sqlStr="select * from country where LifeExpectancy ";
        try {
            con = DriverManager.getConnection(uri, user, password);
        } catch (SQLException e) {
        }
        try {
            sql = con.createStatement();
            rs = sql.executeQuery("select * from country");
            float age1 = 0;
            float age2 = 100;

            while (rs.next()) {
                float LifeExpectancy = rs.getFloat(8);
                String Name = rs.getString(2);
                if (LifeExpectancy >= age1) {
                    age1 = LifeExpectancy;
                    name1 = Name;
                } else if (LifeExpectancy <= age2 && LifeExpectancy != 0.0) {
                    age2 = LifeExpectancy;
                    name2 = Name;
                }
            }
            System.out.println("寿命最长的国家为：" + name1 + ",平均寿命" + age1+"岁");
            System.out.println("寿命最短的国家为：" + name2 + ",平均寿命" + age2+"岁");
            con.close();
        } catch (SQLException e) {
            System.out.println(e);

        }


    }
}
